<!DOCTYPE html>
<html class="x-admin-sm">
{include file='public/header'}
<style>
    .layui-form-label{width: 170px;}
    .layui-input-block{margin-left: 200px;}
</style>
<body>
    <div class="x-body">
        <form class="layui-form" lay-filter="formAjax">
            <div class="layui-form-item">
                <label class="layui-form-label">提交类型：</label>
                <div class="layui-input-block">
                    <input type="radio" name="submit_type" lay-filter="submit_type" value="one" title="单个" checked>
                    <input type="radio" name="submit_type" lay-filter="submit_type" value="batch" title="批量">
                </div>
            </div>
            <div class="layui-form-item" style='display: flex;'>
                <label class="layui-form-label">
                    <span class="x-red">*</span>选择小程序
                </label>
                <div id="GetAuthorizers" style="width: 100%;flex: 1;"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">操作类型：</label>
                <div class="layui-input-block">
                    <input type="radio" name="action" value="add" title="添加">
                    <input type="radio" name="action" value="delete" title="删除">
                    <input type="radio" name="action" value="set" title="覆盖">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">request合法域名：</label>
                <div class="layui-input-block">
                    <input type="text" name="requestdomain" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">socket合法域名：</label>
                <div class="layui-input-block">
                    <input type="text" name="wsrequestdomain" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">uploadFile合法域名：</label>
                <div class="layui-input-block">
                    <input type="text" name="uploaddomain" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">downloadFile合法域名：</label>
                <div class="layui-input-block">
                    <input type="text" name="downloaddomain" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">udp合法域名：</label>
                <div class="layui-input-block">
                    <input type="text" name="udpdomain" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">tcp合法域名：</label>
                <div class="layui-input-block">
                    <input type="text" name="tcpdomain" class="layui-input" autocomplete="off">
                </div>
            </div>
            <button id="submitData" class="layui-btn" lay-submit lay-filter="submitData" style="display: none;" />
        </form>
    </div>
    <script>
        layui.use(["form", "layer"], function () {
            var form = layui.form,
                layer = layui.layer;
            form.on('submit(submitData)', function(data){
                var formData = data.field;
                let url = '/admin/OpenWeixin/modifyServerDomain';
                Object.keys(formData).forEach((item,index)=>{
                    if(item != 'action' && item != 'app_id' ){
                        formData[Object.keys(formData)[index]] = Object.values(formData)[index].split(',')
                    }
                })
                if(form.val("formAjax").submit_type == 'one'){
                    formReloadAjax(url,formData)
                }else{
                    batchTask({
                        app_ids:form.val("formAjax").app_id.split(','),
                        task_method:'modifyServerDomain',
                        task_data:formData
                    })
                }
                return false
            });
            form.on('radio(submit_type)', function(data){
                let app_id = form.val("formAjax").app_id.split(',');
                if(data.value == 'one'){
                    xmSelectGetAuthorizersOption.initValue = app_id.length == 0 ? '' : [app_id[0]]
                    xmSelectGetAuthorizersOption.radio = true;
                    xmSelectGetAuthorizersOption.clickClose = true;
                    xmSelectGetAuthorizersOption.label = {
                        type:'text'
                    };
                }else{
                    xmSelectGetAuthorizersOption.initValue = app_id ?? ''
                    xmSelectGetAuthorizersOption.radio = false;
                    xmSelectGetAuthorizersOption.clickClose = false;
                    xmSelectGetAuthorizersOption.label = {
                        type:'block'
                    };
                    
                }
                xmSelectA(xmSelectGetAuthorizersOption)
            });
        });

        let xmSelectGetAuthorizersOption = {
            initValue:'',//初始值
            el:'#GetAuthorizers',
            url:'/admin/OpenWeixin/getAuthorizersSelect',
            direction:'down',//下拉方向
            isData:true,
            radio:true,
            clickClose:true,
            label: {
                type: 'text'
            },
            pageSize:8,
            prop:{
                name:'app_name',
                value:"app_id"
            },
            name:'app_id',
        }
        xmSelectA(xmSelectGetAuthorizersOption)
    </script>
</body>

</html>